﻿using UnityEngine;

namespace TPF.ObjectCache
{
    /// <summary>
    /// 回收对象及获取对象如何处理的方法
    /// </summary>
    public abstract class PoolRecycleMethod
    {   
        public abstract void OnGetObject(GameObject gameObject, PoolCore poolCore);
        public abstract void OnRecycleObject(GameObject gameObject, PoolCore poolCore);
    }

    /// <summary>
    /// 传统方法，回收时将对象隐藏
    /// </summary>
    public sealed class PoolRecycleMethodDeactive : PoolRecycleMethod
    {
        public override void OnGetObject(GameObject gameObject, PoolCore poolCore)
        {
            gameObject.SetActive(true);
            // 此处不修改gameObject的parent，交给业务逻辑自己处理
        }

        public override void OnRecycleObject(GameObject gameObject, PoolCore poolCore)
        {
			if (poolCore != null)
            {
				gameObject.SetActive(false);
				gameObject.transform.parent = poolCore.transform;
			}
        }
    }

    /// <summary>
    /// 回收时将对象移动到一个较远地方
    /// </summary>
    public sealed class PoolRecycleMethodMoveFarAway : PoolRecycleMethod
    {
        public Vector3 MoveTarget { get; set; }

        public PoolRecycleMethodMoveFarAway()
        {
            // 默认值
            MoveTarget = new Vector3(1000, 1000, 1000);
        }

        public override void OnGetObject(GameObject gameObject, PoolCore poolCore)
        {
            // 此处不修改gameObject的position，交给业务逻辑自己处理
        }

        public override void OnRecycleObject(GameObject gameObject, PoolCore poolCore)
        {
            gameObject.transform.position = MoveTarget;
        }
    }
}